package org.zjh.view.game;


import org.zjh.constant.ImageConstant;
import org.zjh.controller.GameController;
import org.zjh.controller.listener.GamePanelLis;
import org.zjh.controller.listener.PokerFaceUpLis;
import org.zjh.model.Player;
import org.zjh.model.RealPlayer;

import javax.swing.*;
import java.awt.*;

import static org.zjh.constant.ImageConstant.*;

/**
 * @description: 游戏面板
 * @version 1.0
 */

public class GamePanel extends JPanel {


    private JLabel onePointJLabel; //一分标签
    private JLabel twoPointJLabel; //2分标签
    private JLabel threePointJLabel; //3分标签
    private JLabel noCallJLabel; //不叫标签
    private JLabel realPlayerCallPointResultJLabel; //真实玩家叫分结果
    private JLabel computerAPlayerCallPointResultJLabel; //电脑玩家A玩家叫分结果
    private JLabel computerBPlayerCallPointResultJLabel; //电脑玩家B玩家叫分结果
    private JLabel countdownJLabel; // 叫分倒计时
    private JLabel computerAAvatar; //电脑玩家A 头像
    private JLabel computerBAvatar; //电脑玩家A 头像
    private JLabel realPlayerAvatar; //实际玩家头像
    private JLabel faceUpJlabel; //明牌
    private JLabel discardPokersJLabel; //出牌标签
    private JLabel noDiscardPokersJLabel; //不出牌标签
    private JLabel promptJLabel; //提示标签
    private JLabel multipleJLabel; //倍数标签
    private JLabel computerANoDiscardJLabel; //电脑A不叫标签
    private JLabel computerBNoDiscardJLabel; //电脑B不叫标签
    private JLabel realNoDiscardJLabel; //实际玩家不叫标签
    private JLabel machineHostJLabel; //机器人托管标签
    private int boomNum = 0;
    private int rocketNum = 0;
    private int SpringNum = 0;




    public GamePanel() {
        init();
        addListener();
    }

    /**
     * 初始化
     */
    private void init() {
        setLayout(null);

        onePointJLabel = new JLabel(ImageConstant.ONE_POINT_IMAGE);
        twoPointJLabel = new JLabel(ImageConstant.TWO_POINT_IMAGE);
        threePointJLabel = new JLabel(ImageConstant.THREE_POINT_IMAGE);
        noCallJLabel = new JLabel(NO_CALL_POINT_IMAGE);
        countdownJLabel = new JLabel();
        realPlayerCallPointResultJLabel = new JLabel();
        computerAPlayerCallPointResultJLabel = new JLabel();
        computerBPlayerCallPointResultJLabel = new JLabel();
        computerAAvatar = new JLabel();
        computerBAvatar = new JLabel();
        realPlayerAvatar = new JLabel();
        faceUpJlabel = new JLabel(FACE_UP_IMAGE);
        discardPokersJLabel = new JLabel(DISCARD_POKER_IMAGE);
        noDiscardPokersJLabel = new JLabel(NO_DISCARD_POKER_IMAGE);
        promptJLabel = new JLabel(PROMPT_IMAGE);
        multipleJLabel = new JLabel("倍数：0");
        computerANoDiscardJLabel = new JLabel();
        computerBNoDiscardJLabel = new JLabel();
        realNoDiscardJLabel = new JLabel();
        machineHostJLabel = new JLabel(MACHINE_IMAGE);
        ///玩家们的昵称
        JLabel realPlayerNameJLabel = new JLabel("昵称：" + GameController.getInstance().getPlayer().getNickname());
        JLabel computerAPlayerNameLabel = new JLabel("昵称：" + GameController.getInstance().getComputerA().getNickname());
        JLabel computerBPlayerNameLabel = new JLabel("昵称："+ GameController.getInstance().getComputerB().getNickname());

        //玩家们的积分
        JLabel realPlayerScoreJLabel = new JLabel("积分："+ GameController.getInstance().getPlayer().getScore());
        JLabel computerAPlayerScoreJLabel = new JLabel("积分：" + GameController.getInstance().getComputerA().getScore());
        JLabel computerBPlayerScoreJLabel = new JLabel("积分：" + GameController.getInstance().getComputerB().getScore());


        //设置标签对应位置大小
        onePointJLabel.setBounds(400, 450, ONE_POINT_IMAGE.getIconWidth(), ONE_POINT_IMAGE.getIconHeight());
        twoPointJLabel.setBounds(500, 450, TWO_POINT_IMAGE.getIconWidth(), TWO_POINT_IMAGE.getIconHeight());
        threePointJLabel.setBounds(600, 450, THREE_POINT_IMAGE.getIconWidth(), THREE_POINT_IMAGE.getIconHeight());
        noCallJLabel.setBounds(700, 450, NO_CALL_POINT_IMAGE.getIconWidth(), NO_CALL_POINT_IMAGE.getIconHeight());
        realPlayerCallPointResultJLabel.setBounds(550, 400, 80, 40);
        computerAPlayerCallPointResultJLabel.setBounds(200, 200, 80, 40);
        computerBPlayerCallPointResultJLabel.setBounds(950, 200, 80, 40);
        computerAAvatar.setBounds(100, 25, 80, 59);
        computerBAvatar.setBounds(1000, 25, 80, 59);
        realPlayerAvatar.setBounds(100, 500, 80, 59);
        multipleJLabel.setBounds(400, 250, 240, 40);
        faceUpJlabel.setBounds(900, 475, FACE_UP_IMAGE.getIconWidth(), FACE_UP_IMAGE.getIconHeight());
        machineHostJLabel.setBounds(1000,550,MACHINE_IMAGE.getIconWidth(),MACHINE_IMAGE.getIconHeight());
        promptJLabel.setBounds(400, 425, PROMPT_IMAGE.getIconWidth(), PROMPT_IMAGE.getIconHeight());
        discardPokersJLabel.setBounds(550, 425, DISCARD_POKER_IMAGE.getIconWidth(), DISCARD_POKER_IMAGE.getIconHeight());
        noDiscardPokersJLabel.setBounds(700, 425, NO_DISCARD_POKER_IMAGE.getIconWidth(), NO_DISCARD_POKER_IMAGE.getIconHeight());
        computerANoDiscardJLabel.setBounds(150,300,80,40);
        computerBNoDiscardJLabel.setBounds(950,300,80,40);
        realNoDiscardJLabel.setBounds(500,350,80,40);
        realPlayerNameJLabel.setBounds(50,550,300,40);
        computerAPlayerNameLabel.setBounds(200,40,300,40);
        computerBPlayerNameLabel.setBounds(800,40,300,40);
        realPlayerScoreJLabel.setBounds(50,600,200,40);
        computerAPlayerScoreJLabel.setBounds(200,100,300,40);
        computerBPlayerScoreJLabel.setBounds(800,100,300,40);




        countdownJLabel.setFont(new Font("隶书", Font.PLAIN, 40));
        realPlayerCallPointResultJLabel.setFont(new Font("隶书", Font.PLAIN, 40));
        computerAPlayerCallPointResultJLabel.setFont(new Font("隶书", Font.PLAIN, 40));
        computerBPlayerCallPointResultJLabel.setFont(new Font("隶书", Font.PLAIN, 40));
        multipleJLabel.setFont(new Font("隶书", Font.PLAIN, 40));
        computerANoDiscardJLabel.setFont(new Font("隶书", Font.PLAIN, 40));
        computerBNoDiscardJLabel.setFont(new Font("隶书", Font.PLAIN, 40));
        realNoDiscardJLabel.setFont(new Font("隶书", Font.PLAIN, 40));
        realPlayerNameJLabel.setFont(new Font("隶书", Font.PLAIN, 30));
        computerAPlayerNameLabel.setFont(new Font("隶书", Font.PLAIN, 30));
        computerBPlayerNameLabel.setFont(new Font("隶书", Font.PLAIN, 30));
        realPlayerScoreJLabel.setFont(new Font("隶书", Font.PLAIN, 30));
        computerAPlayerScoreJLabel.setFont(new Font("隶书", Font.PLAIN, 30));
        computerBPlayerScoreJLabel.setFont(new Font("隶书", Font.PLAIN, 30));


        //字体加粗
        countdownJLabel.setForeground(Color.BLACK);
        realPlayerCallPointResultJLabel.setForeground(Color.BLACK);
        computerAPlayerCallPointResultJLabel.setForeground(Color.BLACK);
        computerBPlayerCallPointResultJLabel.setForeground(Color.BLACK);
        multipleJLabel.setForeground(Color.BLACK);
        realPlayerNameJLabel.setForeground(Color.BLACK);
        computerAPlayerNameLabel.setForeground(Color.BLACK);
        computerBPlayerNameLabel.setForeground(Color.BLACK);
        realPlayerScoreJLabel.setForeground(Color.BLACK);
        computerAPlayerScoreJLabel.setForeground(Color.BLACK);
        computerBPlayerScoreJLabel.setForeground(Color.BLACK);


        //初始标签默认不可见
        computerAAvatar.setVisible(false);
        computerBAvatar.setVisible(false);
        realPlayerAvatar.setVisible(false);
        faceUpJlabel.setVisible(false);
        multipleJLabel.setVisible(false);
        discardPokersJLabel.setVisible(false);
        noDiscardPokersJLabel.setVisible(false);
        promptJLabel.setVisible(false);
        machineHostJLabel.setVisible(false);

        //一开始叫分JLabel设置不可见等发完牌设置可见
        setCallPointJLabelVisibleFalse();


        add(onePointJLabel);
        add(twoPointJLabel);
        add(threePointJLabel);
        add(noCallJLabel);
        add(countdownJLabel);
        add(realPlayerCallPointResultJLabel);
        add(computerAPlayerCallPointResultJLabel);
        add(computerBPlayerCallPointResultJLabel);
        add(multipleJLabel);
        add(computerAAvatar);
        add(computerBAvatar);
        add(realPlayerAvatar);
        add(faceUpJlabel);
        add(promptJLabel);
        add(discardPokersJLabel);
        add(noDiscardPokersJLabel);
        add(computerANoDiscardJLabel);
        add(computerBNoDiscardJLabel);
        add(realNoDiscardJLabel);
        add(machineHostJLabel);
        add(realPlayerNameJLabel);
        add(computerAPlayerNameLabel);
        add(computerBPlayerNameLabel);
        add(realPlayerScoreJLabel);
        add(computerAPlayerScoreJLabel);
        add(computerBPlayerScoreJLabel);
    }


    /**
     * 添加监听器
     */
    private void addListener() {
        this.addMouseListener(GamePanelLis.getInstance());
        faceUpJlabel.addMouseListener(new PokerFaceUpLis());
    }

    /**
     * 叫分相关标签设置不可见
     */
    public void setCallPointJLabelVisibleFalse() {
        onePointJLabel.setVisible(false);
        twoPointJLabel.setVisible(false);
        threePointJLabel.setVisible(false);
        noCallJLabel.setVisible(false);
    }

    /**
     * 叫分先关标签设置可见
     */
    public void setCallPointJLabelVisibleTrue() {
        onePointJLabel.setVisible(true);
        twoPointJLabel.setVisible(true);
        threePointJLabel.setVisible(true);
        noCallJLabel.setVisible(true);
    }


    /**
     * 重置叫分相关标签
     */
    public void resetCallPointResultJLabelAndCountDownJLabel() {
        realPlayerCallPointResultJLabel.setText("");
        computerAPlayerCallPointResultJLabel.setText("");
        computerBPlayerCallPointResultJLabel.setText("");
        realPlayerCallPointResultJLabel.setText("");
        countdownJLabel.setText("");
    }

    /**
     * 设置头像可见
     */
    public void setAvatarVisibleTrue() {
        computerAAvatar.setVisible(true);
        computerBAvatar.setVisible(true);
        realPlayerAvatar.setVisible(true);
    }


    /**
     * 设置头像不可见
     */
    public void setAvatarVisibleFalse() {
        computerAAvatar.setVisible(false);
        computerBAvatar.setVisible(false);
        realPlayerAvatar.setVisible(false);
    }

    /**
     * 出牌相关标签设置可见
     */
    public void setDiscardPokerVisibleTrue() {
        discardPokersJLabel.setVisible(true);
        noDiscardPokersJLabel.setVisible(true);
        promptJLabel.setVisible(true);
    }

    /**
     * 出牌相关标签设置不可见
     */
    public void setDiscardPokerVisibleFalse() {
        discardPokersJLabel.setVisible(false);
        noDiscardPokersJLabel.setVisible(false);
        promptJLabel.setVisible(false);
    }



    /**
     * 设置倒计时标签对应位置
     * @param countdownJLabel 倒计时标签
     * @param gameController 游戏控制器
     * @param player 当前叫分玩家
     */
    public void setCountdownLabel(JLabel countdownJLabel, GameController gameController, Player player) {
        if (player instanceof RealPlayer) {
            countdownJLabel.setBounds(800, 400, 100, 35);
        } else if (player == gameController.getComputerA()) {
            countdownJLabel.setBounds(200, 150, 100, 35);
        } else {
            countdownJLabel.setBounds(950, 150, 100, 35);
        }
    }

    /**
     * 重置 不出标签内容
     */
    public void resetNoDiscardPokerLabel(){
        computerBNoDiscardJLabel.setText("");
        computerANoDiscardJLabel.setText("");
        realNoDiscardJLabel.setText("");
    }



    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.drawImage(Game_Frame_IMAGE.getImage(), 0, 0, Game_Frame_IMAGE.getIconWidth(), Game_Frame_IMAGE.getIconHeight(), null);
    }


    public JLabel getOnePointJLabel() {
        return onePointJLabel;
    }


    public JLabel getTwoPointJLabel() {
        return twoPointJLabel;
    }


    public JLabel getThreePointJLabel() {
        return threePointJLabel;
    }


    public JLabel getNoCallJLabel() {
        return noCallJLabel;
    }


    public JLabel getRealPlayerCallPointResultJLabel() {
        return realPlayerCallPointResultJLabel;
    }



    public JLabel getComputerAPlayerCallPointResultJLabel() {
        return computerAPlayerCallPointResultJLabel;
    }



    public JLabel getComputerBPlayerCallPointResultJLabel() {
        return computerBPlayerCallPointResultJLabel;
    }



    public JLabel getCountdownJLabel() {
        return countdownJLabel;
    }


    public JLabel getComputerAAvatar() {
        return computerAAvatar;
    }


    public JLabel getComputerBAvatar() {
        return computerBAvatar;
    }


    public JLabel getRealPlayerAvatar() {
        return realPlayerAvatar;
    }



    public JLabel getFaceUpJlabel() {
        return faceUpJlabel;
    }


    public JLabel getDiscardPokersJLabel() {
        return discardPokersJLabel;
    }


    public JLabel getNoDiscardPokersJLabel() {
        return noDiscardPokersJLabel;
    }



    public JLabel getPromptJLabel() {
        return promptJLabel;
    }


    public JLabel getMultipleJLabel() {
        return multipleJLabel;
    }


    public JLabel getComputerANoDiscardJLabel() {
        return computerANoDiscardJLabel;
    }



    public JLabel getComputerBNoDiscardJLabel() {
        return computerBNoDiscardJLabel;
    }



    public JLabel getRealNoDiscardJLabel() {
        return realNoDiscardJLabel;
    }


    public int getBoomNum() {
        return boomNum;
    }

    public void setBoomNum(int boomNum) {
        this.boomNum = boomNum;
    }

    public int getRocketNum() {
        return rocketNum;
    }

    public void setRocketNum(int rocketNum) {
        this.rocketNum = rocketNum;
    }

    public int getSpringNum() {
        return SpringNum;
    }

    public void setSpringNum(int springNum) {
        SpringNum = springNum;
    }

    public JLabel getMachineHostJLabel() {
        return machineHostJLabel;
    }


}
